class Solution:
    """
    264. 丑数 II
    https://leetcode-cn.com/problems/ugly-number-ii/submissions/
    @date: 2020年12月31日19:48:10
    @author: mizzle rain
    """
    def nthUglyNumber(self, n: int) -> int:
        p2, p3, p5 = 0, 0, 0
        nums = [1]
        while n > 1:
            t = min(nums[p2] * 2, nums[p3] * 3, nums[p5] * 5)
            nums.append(t)
            if t == nums[p2] * 2:
                p2 += 1
            if t == nums[p3] * 3:
                p3 += 1
            if t == nums[p5] * 5:
                p5 += 1
            n -= 1
        return nums[-1]
